import Vue from "vue";

// 按需引入 element-ui 组件
import "element-ui/lib/theme-chalk/index.css";//element-ui的css
import "./helper/registerElementComponents.js";
import ElementUI from 'element-ui' //element-ui的全部组件
Vue.use(ElementUI) //使用elementUI

import App from "./App.vue";
import router from "./router";
import "@/assets/style/reset.css";
import "@/assets/style/global.css";

// 注册自定义组件
import "@/helper/registerGlobalComponents.js";

// 引入请求实例
import request from "@/helper/request";

// 日期格式化过滤器

import { formatDate } from "@/helper/utilities";

// 引入loading组件

import CustomLoading from "@/components/Loading/main";
import PopupProgress from "@/components/popup-progress";
import { Message } from 'element-ui'

// 开发环境捕获错误插件

// import NotificationPlugin from "./helper/notification.plugin";

// -----------zhou----------------
import axios from 'axios'
import NProgress from 'nprogress' // 引入nprogress插件
import store from './store'

// 配置axios默认值
axios.defaults.baseURL = '/api'  // 确保这里配置正确
axios.defaults.headers.post['Content-Type'] = 'application/json'

// 请求拦截器
axios.interceptors.request.use(config => {
  const token = sessionStorage.getItem('JWT_TOKEN')
  if (token) {
    config.headers['Authorization'] = token
  }
  return config
}, error => {
  return Promise.reject(error)
})

// 响应拦截器
axios.interceptors.response.use(response => {
  return response.data
}, error => {
  console.error('请求错误:', error)
  return Promise.reject(error)
})

Vue.prototype.$axios = axios

if (process.env.NODE_ENV !== "production") {
  Vue.createElement = new Vue().$createElement;
  // Vue.use(NotificationPlugin);
  Vue.config.devtools = true;
}

// 创建axios实例
axios.create({
  // axios中请求配置有baseURL选项，表示请求URL公共部分
  // baseURL: 'http://localhost:9001',
  baseURL: process.env.VUE_APP_BASE_API,
  // 超时
  timeout: 10000
})
// 感觉这一段没有用
Vue.prototype.$http = axios.create({
  baseURL: "/api",
  headers:{
    post: {'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'}
  }
})

// 使用loading 组件

Vue.use(CustomLoading);
Vue.use(PopupProgress);

// 注册日期格式化过滤器

Vue.filter("formatDate", formatDate);

Vue.config.productionTip = false;
Vue.prototype.request = request;

import {
  Button,
  Table,
  TableColumn,
  Tabs,
  TabPane,
  Pagination,
  Dialog,
  Form,
  FormItem,
  Input,
  Select,
  Option,
  Rate,
  Loading
} from 'element-ui'

Vue.use(Button)
Vue.use(Table)
Vue.use(TableColumn)
Vue.use(Tabs)
Vue.use(TabPane)
Vue.use(Pagination)
Vue.use(Dialog)
Vue.use(Form)
Vue.use(FormItem)
Vue.use(Input)
Vue.use(Select)
Vue.use(Option)
Vue.use(Rate)
Vue.use(Loading)

// Message 组件需要这样注册
Vue.prototype.$message = Message

let vue  = new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");

export default vue;
